package com.riant.day04.demo2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * @Classname Test1
 * @Description TODO
 * @Date 2021/3/11 23:17
 * @Created by 张斌
 */
public class Test1 {
    public static void main(String[] args) {
        Collection<String> collection=new ArrayList<>();
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("ddd");
        String[] arr=new String[3];
        arr[0]="eee";
        String[] str=collection.toArray(arr);
        System.out.println(Arrays.toString(str));
        System.out.println(str==arr);
        collection.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println("当前元素是："+s);
            }
        });


        Collection<String> collection1=new ArrayList<>();
        collection1.addAll(collection);
        Iterator<String> iterator=collection1.iterator();
        while (iterator.hasNext()){
            System.out.println("当前元素是："+iterator.next());
        }
    }
}
